import csv
import os
import pickle

from pandas import DataFrame

import logger

log = logger.get_logger()


def read_pkl(path) -> DataFrame:
    """
    读取pkl文件
    :rtype: object
    :param path: 文件相对路径
    :return: DataFrame对象
    """
    datasetAbsPath = os.path.abspath(path)
    log.info("the abs path of pkl file:" + datasetAbsPath)
    with open(datasetAbsPath, 'rb') as file:
        # print(file)
        dataSet = pickle.load(file)
    return dataSet


def read_csv(path) -> list:
    """
    读取csv文件
    :param path: 文件路径
    :return: List
    """
    absPath = os.path.abspath(path)
    log.info("the abs path of csv file:" + absPath)
    with open(absPath, "r") as file:
        reader = csv.reader(file)
        return list(reader)


def read_txt(path) -> list:
    """
    读取txt文件
    :param path:
    :return:
    """
    absPath = os.path.abspath(path)
    log.info("the abs path of txt file:" + absPath)
    with open(absPath, "r") as file:
        return list(eval(file.read()))
